package com.fwj.auth.config.handle;

import com.alibaba.fastjson.JSON;
import com.fwj.core.common.model.ResponseDTO;
import com.fwj.core.common.model.ResponseEnum;
import org.springframework.http.MediaType;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.web.authentication.AuthenticationFailureHandler;
import org.springframework.stereotype.Component;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * @Author: fwj
 * @Data: 2022/2/20 21:24
 * @Version 1.0
 * @Description:
 */

@Component
public class AuthLoginFailureHandle implements AuthenticationFailureHandler {

    @Override
    public void onAuthenticationFailure(HttpServletRequest httpServletRequest, HttpServletResponse resp, AuthenticationException e) throws IOException, ServletException {
        ResponseDTO responseDTO = new ResponseDTO();
        responseDTO.fail(ResponseEnum.LOGIN_PASSWORD_ERROR);
        ResponseUtil.response(resp, responseDTO);
    }
}
